package com.xiaotao.config;

import com.xiaotao.DailyRedisUpdateTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail sampleJobDetail() {
        return JobBuilder.newJob(DailyRedisUpdateTask.class)
                .withIdentity("dailyRedisUpdateTask")
                .storeDurably()
                .build();
    }

//    @Bean
//    public Trigger sampleJobTrigger() {
//        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//                .withIntervalInSeconds(10)  // 每 10 秒执行一次
//                .repeatForever();
//
//        return TriggerBuilder.newTrigger()
//                .forJob(sampleJobDetail())
//                .withIdentity("sampleJobTrigger")
//                .withSchedule(scheduleBuilder)
//                .build();
//    }

    @Bean
    public Trigger cronJobTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(sampleJobDetail())
                .withIdentity("cronJobTrigger")
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ?"))  // 每天零点执行
                .build();
    }
}